<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>index.js</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../../../../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../../../../../css/github.css" type="text/css" media="screen" />
<script src="../../../../../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../../../../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        
        <h1>
            index.js
        </h1>
        <ul class="files">
            
            <li>
                lib/assets/javascripts/sale_app/cart_items/index.js
                
            </li>
            <li>Last modified: 2017-02-10 16:58:03 +0800</li>
        </ul>
    </div>

    <div id="bodyContent">
        <div id="content">
  
    <div class="description">
      
<p>jQuery(function($){</p>

<pre><code>// edit quantity in cart items
$(&quot;input#add_to_cart_items_quantity&quot;).keyup(function(e){
  var _this = this
      var itemId = $(this).parent().data(&quot;id&quot;);
      var currentNum = $(&quot;input.js-buy-num-&quot;+ itemId).val();
      var price = $(&quot;div#js-item-price-&quot;+ itemId).text();
      var storeId = getUrlParam(&quot;store_id&quot;);
      var csrf = $(&quot;input#js-cart-item-index&quot;).val();
      if ( e.which == 13 ) {
       e.preventDefault();
      };
      if(!isNumber(currentNum)){
              // is not a number
    console.log(&quot;这里不是数字了&quot;);
              showErrorView(&quot;请输入正确的数字!&quot;);
              $.ajax({
                      // update quantity
                      url: &quot;/api/cart_items/&quot;+ itemId,
                      method: &quot;put&quot;,
                      data: {quantity: 1, store_id: storeId},
                      headers: {
                                                              &#39;X-CSRF-Token&#39;: csrf
                                                      },
                      success: function(data){
                              if(data.status == true){
                                      $(&quot;input.js-buy-num-&quot;+ itemId).val(1);
                                      $(&quot;div#js-item-amount-&quot;+ itemId).text(multiplied(data.price, 1));
                                      $(&quot;span.js-cart-total-amount em&quot;).text(&quot;¥ &quot;+ data.total_amount)
                              }
                      }
              });//end ajax

      }else {
              // is a number
              // var amount = price * currentNum * 10000 / 10000
              $.ajax({
                      // update quantity
                      url: &quot;/api/cart_items/&quot;+ itemId,
                      method: &quot;put&quot;,
                      data: {quantity: currentNum, store_id: storeId},
                      headers: {
                                                              &#39;X-CSRF-Token&#39;: csrf
                                                      },
                      success: function(data){
                              if(data.status == true){
                                      $(&quot;div#js-item-amount-&quot;+ itemId).text(multiplied(data.price, currentNum));
                                      $(&quot;span.js-cart-total-amount em&quot;).text(&quot;¥ &quot;+ data.total_amount)
                              }
                      }
              });//end ajax

      }
});
// end edit cart items quantity

//strat to remove cart item
$(&quot;a.js-remove-cart-item&quot;).on(&quot;click&quot;, function(){
              var itemId = $(this).data(&quot;id&quot;);
              var csrf = $(&quot;input#js-cart-item-index&quot;).val();
              var storeId = getUrlParam(&quot;store_id&quot;);
              BootstrapDialog.show({
          title: &#39;提示框:&#39;,
          message: &quot;确定移除该商品?&quot;,
          buttons: [{
              label: &#39;取消&#39;,
              action: function(dialog) {
                  dialog.close();
              }
          }, {
              label: &#39;确定&#39;,
              cssClass: &#39;btn-primary&#39;,
              action: function(dialog){
                                                                      $.ajax({
                                                                              url: &quot;/api/cart_items/&quot;+ itemId +&quot;/remove&quot;,
                                                                              method: &quot;put&quot;,
                                                                              data: {store_id: storeId},
                                                                              headers: {
                                                                                                                      &#39;X-CSRF-Token&#39;: csrf
                                                                                                              },
                                                                              success: function(data){
                                                                                      if(data.status == true){
                                                                                              $(&quot;div.js-cart-item-div-&quot;+ itemId).remove();
                                                                                              $(&quot;span.js-cart-total-amount em&quot;).text(&quot;¥ &quot;+ data.total_amount)
                                                                                              dialog.close();
                                                                                      }
                                                                              }
                                                                      })
              }
          }]
      });

      });
// end to remove cart item

$(&quot;a.js-to-order-new&quot;).on(&quot;click&quot;, function(e){
  console.log(getUrlParam(&quot;store_id&quot;));
              var count = $(this).data(&quot;items&quot;);
  var customCount = $(this).data(&quot;custom-count&quot;);
              if (count &lt;= 0){
                      e.preventDefault();
                      showErrorView(&quot;购物车为空，请选购产品!&quot;);
                      return false
              }else if (customCount &gt; 0){
    BootstrapDialog.show({
            title: &#39;提示框:&#39;,
            message: &quot;检测到存在自定义商品，已确认联系商家核对价格？&quot;,
            buttons: [{
                label: &#39;取消&#39;,
                action: function(dialog) {
                    e.preventDefault();
                    dialog.close();
                }
            }, {
                label: &#39;确定&#39;,
                cssClass: &#39;btn-primary&#39;,
                action: function(dialog){
                                                                      dialog.close();
                  location.href = &quot;/sales/store_orders/new?store_id=&quot;+getUrlParam(&quot;store_id&quot;)
                }
            }]
        });
  }else {
    location.href = &quot;/sales/store_orders/new?store_id=&quot;+getUrlParam(&quot;store_id&quot;)
  }

      })</code></pre>

<p>})</p>

    </div>
  


  


  
  


  


  

  



  

    

    

    


    


    <!-- Methods -->
              </div>

    </div>
  </body>
</html>
